package com.songshuai.webapi.common.component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.songshuai.webapi.common.httpclient.HttpClientUtil;
import org.springframework.stereotype.Component;

/**
 * 微信相关组件
 * @Author: lhx
 * @Date: 2019/3/15 18:58
 */
@Component
public class WeChatComponent {


    //登陆接口地址
    private static final String code2Session = "https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";



    /**
     * 微信登陆接口
     * @param code
     * @return
     */
    public JSONObject jscode2session(String code,String appid,String secret){
        String url = String.format(code2Session,appid,secret,code);
        String msg = HttpClientUtil.sendGet(url, null);
        return JSON.parseObject(msg);

    }











}
